<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对快照监控内存</title>
  </head>
  <body>
    <button id="btn">add</button>
    <script>
      var tmpEl;

      const btnEl = document.getElementById('btn');

      function test() {
        var ul = document.createElement('ul');
        for (var i = 0; i < 10; i++) {
          ul.appendChild(document.createElement('li'));
        }
        tmpEl = ul;

        // 分离dom的解决方法，用完销毁
        // tmpEl = null;
      }

      btnEl.addEventListener('click', test);
    </script>
  </body>
</html>
